package mao.leetcode.competation;

import java.util.Arrays;

public class weekCompetation182 {
    public int findLucky(int[] arr) {
        Arrays.sort(arr);
        int count = 1;
        for(int i=arr.length-2;i>=0;i--){
            if(arr[i] == arr[i+1]){
                count++;
                if(count == arr[i] && ((i>1 && arr[i-1] != arr[i]) || i==0)){
                    return arr[i];
                }
            }else {
                count=1;
            }
        }
        if(arr[0]==1 && count==1) return 1;
        return -1;
    }

    public int numTeams(int[] rating) {
        int ans = 0;
        for(int i=0;i<rating.length;i++){
            for (int j = i+1; j < rating.length; j++) {
                for (int k = j+1; k < rating.length; k++) {
                    if(rating[i]<rating[j] && rating[j]<rating[k]
                        || rating[i]>rating[j] && rating[j]>rating[k]){
                        ans++;
                    }
                }
            }
        }
        return  ans;
    }
}
